﻿using System.ComponentModel;
using System.Windows.Forms;


namespace ExtensibleEventViewer.EventLogFilters
{
	public partial class EventLogRecordTypeFilterControl : UserControl
	{
		public EventLogRecordTypeFilter Filter
		{
			get; 
			set;
		}

		public EventLogRecordTypeFilterControl()
		{
			InitializeComponent();
		}

		protected override void OnLoad(System.EventArgs e)
		{
			cbError.Checked = Filter.Settings.EnableErrorType;
			cbInformation.Checked = Filter.Settings.EnableInformationType;
			cbWarning.Checked = Filter.Settings.EnableWarningType;
			cbUnknown.Checked = Filter.Settings.EnableUnknownType;

			if (ParentForm != null)
			{
				ParentForm.Closing += ParentForm_Closing;
			}

			base.OnLoad(e);
		}

		void ParentForm_Closing(object sender, CancelEventArgs e)
		{
			if (ParentForm != null && ParentForm.DialogResult == DialogResult.OK)
			{
				EventLogRecordTypeFilterSettings settings = new EventLogRecordTypeFilterSettings();

				settings.EnableErrorType = cbError.Checked;
				settings.EnableInformationType = cbInformation.Checked;
				settings.EnableWarningType = cbWarning.Checked;
				settings.EnableUnknownType = cbUnknown.Checked;

				Filter.Settings = settings;

				Filter.Save();
			}
		}
	}
}